<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>修改商品类型</title>
    <!-- title -->
    <% include ../public/page_title.html%>
</head>
<body class="main_body">
    <fieldset class="layui-elem-field" style="margin:10px;">
        <legend>修改商品类型</legend>
        <div class="layui-field-box">
            <div class="layui-row">
                <div class="layui-col-md9">
                    <form class="layui-form" style='padding:15px 0;'>
                        <div class="layui-form-item">
                            <label class="layui-form-label">类型名称</label>
                            <div class="layui-input-block">
                                <input type="text" value="<%=list.title%>" name="title" class="layui-input" lay-verify="title" placeholder="类型名称">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">类型描述</label>
                            <div class="layui-input-block">
                                <textarea name="description" placeholder="类型描述" lay-verify="description" class="layui-textarea"><%=list.description%></textarea>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <div class="layui-input-block">
                                <button id="editType" class="layui-btn" lay-submit lay-filter="editType">保存修改</button>
                                <a href="<%=adminName%>/goodsType" class="layui-btn layui-btn-primary">返回</a>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </fieldset>
	<script type="text/javascript" src="/public/admin/layui/layui.js"></script>
    <script type="text/javascript" src="/public/admin/js/index.js"></script>
    <script>
         layui.use(['form','jquery'], function() {
            var form = layui.form,
                $ = layui.jquery;
            //自定义验证规则
            form.verify({
                title: function(value) {
                    if(value.length ==0 ) {
                        return '请输入类型名称';
                    }
                },
                description: function(value) {
                    if(value.length ==0 ) {
                        return '请输入类型描述';
                    }
                },
            });
            //监听提交
            form.on('submit(editType)', function(data) {
                data.field._csrf = "<%=csrf%>";
                data.field.id = "<%=id%>";
                $('#editType').attr('disabled',true);
                console.log(data.field)
                $.ajax({
                    type:'post',
                    data:data.field,
                    dataType:'json',
                    url:'<%=adminName%>/goodsType/doedit',
                    success:function(res){
                        console.log(res);
                        if(res.code===0){
                            layer.msg(res.msg);
                            setTimeout(function(){
                                window.location.href = "<%=adminName%>/goodsType"
                            },500)
                        }else{
                            layer.msg(res.msg);
                            $('#editType').removeAttr('disabled');
                        }
                        
                    },
                    error:function(err){
                        layer.msg('后台出错');
                        $('#editType').removeAttr('disabled');
                    }
                })
                return false;
            })
        })
    </script>
</body>
</html>